package gui;

import classes.CargoComissao;
import classes.CargoEfetivo;
import classes.Lotacao;
import classes.Servidor;
import java.awt.event.KeyEvent;
import org.apache.commons.lang3.StringUtils;
import controlador.ServidorControlador;
import erro.ConexaoException;
import erro.ConsultaException;
import erro.GeralException;
import fachada.Fachada;
import java.util.ArrayList;
import java.util.StringTokenizer;
import javax.swing.JOptionPane;
import rn.CriptografarSenha;

/**
 *
 * @author Roberta
 */
public class ServidorCadastrar extends javax.swing.JFrame {

    /** Creates new form ServidorCadastrar */
    public ServidorCadastrar() {
        initComponents();
        carregarCombos();
        this.setLocationRelativeTo(null);
    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jTabbedPane4 = new javax.swing.JTabbedPane();
        frameDadosProf = new javax.swing.JPanel();
        jPanel1 = new javax.swing.JPanel();
        jLabel42 = new javax.swing.JLabel();
        textMatricula = new javax.swing.JTextField();
        try{ 
            javax.swing.text.MaskFormatter mat= new javax.swing.text.MaskFormatter("#####-#"); 
            textMatricula = new javax.swing.JFormattedTextField(mat); 
        } 
        catch (Exception e){ 
        }
        jLabel43 = new javax.swing.JLabel();
        textEmailProf = new javax.swing.JTextField();
        jLabel30 = new javax.swing.JLabel();
        jLabel45 = new javax.swing.JLabel();
        textTelSetor = new javax.swing.JTextField();
        try{ 
            javax.swing.text.MaskFormatter tel= new javax.swing.text.MaskFormatter("####-####"); 
            textTelSetor = new javax.swing.JFormattedTextField(tel); 
        } 
        catch (Exception e){ 
        }
        jLabel48 = new javax.swing.JLabel();
        cbLotacao = new javax.swing.JComboBox();
        jLabel47 = new javax.swing.JLabel();
        cbCargoC = new javax.swing.JComboBox();
        jLabel46 = new javax.swing.JLabel();
        cbCargoE = new javax.swing.JComboBox();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        jLabel10 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        textTelFunc = new javax.swing.JTextField();
        try{ 
            javax.swing.text.MaskFormatter tel= new javax.swing.text.MaskFormatter("####-####"); 
            textTelFunc = new javax.swing.JFormattedTextField(tel); 
        } 
        catch (Exception e){ 
        }
        frameDadosPessoais = new javax.swing.JPanel();
        jPanel2 = new javax.swing.JPanel();
        jLabel8 = new javax.swing.JLabel();
        jLabel36 = new javax.swing.JLabel();
        jLabel35 = new javax.swing.JLabel();
        jLabel32 = new javax.swing.JLabel();
        textNome = new javax.swing.JTextField();
        jLabel34 = new javax.swing.JLabel();
        textCpf = new javax.swing.JTextField();
        try{ 
            javax.swing.text.MaskFormatter cpf= new javax.swing.text.MaskFormatter("###.###.###-##"); 
            textCpf = new javax.swing.JFormattedTextField(cpf); 
        } 
        catch (Exception e){ 
        }
        textEmail = new javax.swing.JTextField();
        textTel = new javax.swing.JTextField();
        try{ 
            javax.swing.text.MaskFormatter tel= new javax.swing.text.MaskFormatter("## ####-####"); 
            textTel = new javax.swing.JFormattedTextField(tel); 
        } 
        catch (Exception e){ 
        }
        textTel2 = new javax.swing.JTextField();
        try{ 
            javax.swing.text.MaskFormatter tel= new javax.swing.text.MaskFormatter("## ####-####"); 
            textTel2 = new javax.swing.JFormattedTextField(tel); 
        } 
        catch (Exception e){ 
        }
        jLabel33 = new javax.swing.JLabel();
        textRua = new javax.swing.JTextField();
        jLabel37 = new javax.swing.JLabel();
        textNumero = new javax.swing.JTextField();
        jLabel38 = new javax.swing.JLabel();
        textBairro = new javax.swing.JTextField();
        jLabel39 = new javax.swing.JLabel();
        textCidade = new javax.swing.JTextField();
        jLabel40 = new javax.swing.JLabel();
        textEstado = new javax.swing.JTextField();
        textCep = new javax.swing.JTextField();
        try{ 
            javax.swing.text.MaskFormatter cep= new javax.swing.text.MaskFormatter("#####-###"); 
            textCep = new javax.swing.JFormattedTextField(cep); 
        } 
        catch (Exception e){ 
        }
        jLabel41 = new javax.swing.JLabel();
        jLabel1 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel11 = new javax.swing.JLabel();
        textData = new com.toedter.calendar.JDateChooser();
        jLabel2 = new javax.swing.JLabel();
        jLabel12 = new javax.swing.JLabel();
        jLabel13 = new javax.swing.JLabel();
        checkEmail = new javax.swing.JCheckBox();
        jLabel44 = new javax.swing.JLabel();
        jPanel3 = new javax.swing.JPanel();
        btIncluir = new javax.swing.JButton();
        btLimpar = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Cadastrar Servidor");

        jPanel1.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        jLabel42.setText("Matricula:");

        jLabel43.setText("E-mail:");

        jLabel30.setText("@recife.pe.gov.br");

        jLabel45.setText("Telefone do setor:");

        jLabel48.setText("Lotação:");

        jLabel47.setText("Cargo Comissão:");

        jLabel46.setText("Cargo Efetivo:");

        jLabel5.setText("*");

        jLabel6.setText("*");

        jLabel9.setText("*");

        jLabel10.setText("*");

        jLabel7.setText("Telefone funcional:");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabel45)
                            .addComponent(jLabel43)
                            .addComponent(jLabel42)
                            .addComponent(jLabel7)
                            .addComponent(jLabel48))
                        .addGap(18, 18, 18)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(cbLotacao, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(5, 5, 5)
                                .addComponent(jLabel10))
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(textMatricula, javax.swing.GroupLayout.PREFERRED_SIZE, 64, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(5, 5, 5)
                                .addComponent(jLabel5))
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(textEmailProf, javax.swing.GroupLayout.PREFERRED_SIZE, 185, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(5, 5, 5)
                                .addComponent(jLabel30)
                                .addGap(6, 6, 6)
                                .addComponent(jLabel6))
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                    .addComponent(textTelFunc, javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(textTelSetor, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 112, Short.MAX_VALUE))
                                .addGap(5, 5, 5)
                                .addComponent(jLabel9))))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(21, 21, 21)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabel46)
                            .addComponent(jLabel47))
                        .addGap(18, 18, 18)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(cbCargoE, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(cbCargoC, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addContainerGap(47, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel42, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(textMatricula, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel5))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel43)
                    .addComponent(textEmailProf, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel30)
                    .addComponent(jLabel6))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel45)
                    .addComponent(textTelSetor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel9))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel7)
                    .addComponent(textTelFunc, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel48)
                    .addComponent(cbLotacao, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel10))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel47)
                    .addComponent(cbCargoC, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel46)
                    .addComponent(cbCargoE, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );

        javax.swing.GroupLayout frameDadosProfLayout = new javax.swing.GroupLayout(frameDadosProf);
        frameDadosProf.setLayout(frameDadosProfLayout);
        frameDadosProfLayout.setHorizontalGroup(
            frameDadosProfLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(frameDadosProfLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
        frameDadosProfLayout.setVerticalGroup(
            frameDadosProfLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(frameDadosProfLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(243, Short.MAX_VALUE))
        );

        jTabbedPane4.addTab("Dados Profissionais", frameDadosProf);

        jPanel2.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        jLabel8.setText("CPF:");

        jLabel36.setText("E-mail Pessoal:");

        jLabel35.setText("Nome:");

        jLabel32.setText("Telefone 1:");

        jLabel34.setText("Telefone 2:");

        jLabel33.setText("Rua:");

        jLabel37.setText("Número:");

        jLabel38.setText("Bairro:");

        jLabel39.setText("Cidade:");

        jLabel40.setText("UF:");

        textCep.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                textCepActionPerformed(evt);
            }
        });

        jLabel41.setText("CEP:");

        jLabel1.setText("*");

        jLabel3.setText("*");

        jLabel4.setText("*");

        jLabel11.setText("Data Nasc.:");

        jLabel2.setText("*");

        jLabel12.setText("ex.: 01/01/2011");

        jLabel13.setText("*");

        checkEmail.setText("Deseja receber informações neste e-mail?");

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel32)
                    .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                        .addComponent(jLabel41)
                        .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabel40)
                            .addComponent(jLabel39)
                            .addComponent(jLabel38)
                            .addComponent(jLabel37)
                            .addComponent(jLabel33)
                            .addComponent(jLabel34)
                            .addComponent(jLabel36)
                            .addComponent(jLabel8)
                            .addComponent(jLabel35)
                            .addComponent(jLabel11))))
                .addGap(18, 18, 18)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(textTel, javax.swing.GroupLayout.PREFERRED_SIZE, 110, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(5, 5, 5)
                        .addComponent(jLabel4))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(textData, javax.swing.GroupLayout.PREFERRED_SIZE, 145, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(4, 4, 4)
                        .addComponent(jLabel13)
                        .addGap(18, 18, 18)
                        .addComponent(jLabel12))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(textCpf, javax.swing.GroupLayout.PREFERRED_SIZE, 147, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(5, 5, 5)
                        .addComponent(jLabel2))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(textNome, javax.swing.GroupLayout.PREFERRED_SIZE, 250, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(5, 5, 5)
                        .addComponent(jLabel1))
                    .addComponent(checkEmail)
                    .addComponent(textTel2, javax.swing.GroupLayout.PREFERRED_SIZE, 110, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(textRua, javax.swing.GroupLayout.PREFERRED_SIZE, 273, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(textNumero, javax.swing.GroupLayout.PREFERRED_SIZE, 81, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(textBairro, javax.swing.GroupLayout.PREFERRED_SIZE, 215, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(textEstado, javax.swing.GroupLayout.PREFERRED_SIZE, 34, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(textCep, javax.swing.GroupLayout.PREFERRED_SIZE, 107, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addComponent(textCidade, javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(textEmail, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 291, Short.MAX_VALUE))
                        .addGap(5, 5, 5)
                        .addComponent(jLabel3)))
                .addGap(57, 57, 57))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel35)
                    .addComponent(textNome, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel1))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel8)
                    .addComponent(textCpf, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel2))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel36)
                    .addComponent(textEmail, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel3))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(checkEmail)
                .addGap(7, 7, 7)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel11)
                    .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(textData, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel13)
                            .addComponent(jLabel12))))
                .addGap(18, 18, 18)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(textTel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel4)
                    .addComponent(jLabel32))
                .addGap(6, 6, 6)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel34)
                    .addComponent(textTel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel33)
                    .addComponent(textRua, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel37)
                    .addComponent(textNumero, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel38)
                    .addComponent(textBairro, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel39)
                    .addComponent(textCidade, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel40)
                    .addComponent(textEstado, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel41)
                    .addComponent(textCep, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(86, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout frameDadosPessoaisLayout = new javax.swing.GroupLayout(frameDadosPessoais);
        frameDadosPessoais.setLayout(frameDadosPessoaisLayout);
        frameDadosPessoaisLayout.setHorizontalGroup(
            frameDadosPessoaisLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(frameDadosPessoaisLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
        frameDadosPessoaisLayout.setVerticalGroup(
            frameDadosPessoaisLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(frameDadosPessoaisLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );

        jTabbedPane4.addTab("Dados Pessoais", frameDadosPessoais);

        jLabel44.setText("* Campos obrigatórios.");

        btIncluir.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagens/adicionar.png"))); // NOI18N
        btIncluir.setText("Incluir");
        btIncluir.setToolTipText("Digite os dados do Servidor e clique para incluir.");
        btIncluir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btIncluirActionPerformed(evt);
            }
        });
        btIncluir.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                btIncluirKeyPressed(evt);
            }
        });

        btLimpar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagens/limpar.png"))); // NOI18N
        btLimpar.setText("Limpar");
        btLimpar.setToolTipText("Clique para limpar os campos da aba selecionada.");
        btLimpar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btLimparActionPerformed(evt);
            }
        });
        btLimpar.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                btLimparKeyPressed(evt);
            }
        });

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(btIncluir, javax.swing.GroupLayout.DEFAULT_SIZE, 99, Short.MAX_VALUE)
                    .addComponent(btLimpar, javax.swing.GroupLayout.DEFAULT_SIZE, 99, Short.MAX_VALUE))
                .addContainerGap())
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addComponent(btIncluir)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btLimpar)
                .addContainerGap(56, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(jTabbedPane4, javax.swing.GroupLayout.DEFAULT_SIZE, 487, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jLabel44))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jTabbedPane4, javax.swing.GroupLayout.DEFAULT_SIZE, 535, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jLabel44))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(32, 32, 32)
                        .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btLimparActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btLimparActionPerformed
        limparTela();
    }//GEN-LAST:event_btLimparActionPerformed

    private void btIncluirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btIncluirActionPerformed
        try {
            Fachada f = new Fachada();
            Servidor s = new Servidor();
            Lotacao l = new Lotacao();
            CargoComissao cc = new CargoComissao();
            CargoEfetivo ce = new CargoEfetivo();
            String cpf = textCpf.getText();
            cpf = cpf.replaceAll("[^0-9]", "");
            ServidorControlador.cpf = cpf;
            String matr = textMatricula.getText();
            matr = matr.replaceAll("[^0-9]", "");
            s.setMatricula(matr);
            ServidorControlador.matricula = s.getMatricula();
            String nome = textNome.getText().toLowerCase().trim();
            StringTokenizer stN = new StringTokenizer(nome, " ");
            String convertido = "";
            while (stN.hasMoreTokens()) {
                String fMaiuscula = StringUtils.capitalize(stN.nextToken().trim() + " ");
                convertido += fMaiuscula;
            }
            s.setNome(convertido);
            s.setCpf(cpf);
            s.setNasc(textData.getDate());
            s.setLogin(textEmailProf.getText().toLowerCase().trim());
            s.setEmailPessoal(textEmail.getText().toLowerCase().trim());
            s.setTelefone1(textTel.getText());
            s.setTelefone2(textTel2.getText());
            s.setTelefoneSetor(textTelSetor.getText());
            s.setEmailProf(textEmailProf.getText().toLowerCase().trim() + "@recife.pe.gov.br");
            if (checkEmail.isSelected()) {
                s.setEmail(1);//Se quiser receber informações no e-mail pessoal.
            }else{
                s.setEmail(0);
            }
            String rua = textRua.getText().toLowerCase().trim();
            StringTokenizer stR = new StringTokenizer(rua, " ");
            convertido = "";
            while (stR.hasMoreTokens()) {
                String fMaiuscula = StringUtils.capitalize(stR.nextToken().trim() + " ");
                convertido += fMaiuscula;
            }
            s.setRua(convertido);
            s.setNumero(textNumero.getText());

            String bairro = textBairro.getText().toLowerCase().trim();
            StringTokenizer stB = new StringTokenizer(bairro, " ");
            convertido = "";
            while (stB.hasMoreTokens()) {
                String fMaiuscula = StringUtils.capitalize(stB.nextToken().trim() + " ");
                convertido += fMaiuscula;
            }
            s.setBairro(convertido);

            String cidade = textCidade.getText().toLowerCase().trim();
            StringTokenizer stC = new StringTokenizer(cidade, " ");
            convertido = "";
            while (stC.hasMoreTokens()) {
                String fMaiuscula = StringUtils.capitalize(stC.nextToken().trim() + " ");
                convertido += fMaiuscula;
            }
            s.setCidade(convertido);
            s.setEstado(textEstado.getText().toUpperCase().trim());
            s.setCep(textCep.getText());
            s.setNivelAcesso(3);
            s.setSenha(CriptografarSenha.encripta("123456"));
            s.setTelefoneFunc(textTelFunc.getText());
            ArrayList<Lotacao> listaLot = new ArrayList<Lotacao>();
            listaLot = f.listar(l);
            l.setLotacao_id(listaLot.get(cbLotacao.getSelectedIndex()).getLotacao_id());
            l = f.pesquisar(l);
            s.setLotacao(l);
            ArrayList<CargoComissao> listaCc = new ArrayList<CargoComissao>();
            listaCc = f.listar(cc);
            cc.setCargoC_id(listaCc.get(cbCargoC.getSelectedIndex()).getCargoC_id());
            cc = f.pesquisar(cc);
            s.setCargoC(cc);

            ArrayList<CargoEfetivo> listaCe = new ArrayList<CargoEfetivo>();
            listaCe = f.listar(ce);
            ce.setCargoE_id(listaCe.get(cbCargoE.getSelectedIndex()).getCargoE_id());
            ce = f.pesquisar(ce);
            s.setCargoE(ce);
            if (s.getCargoC().getCargoC_id() == 1 && s.getCargoE().getCargoE_id() == 1) {
                JOptionPane.showMessageDialog(null, "Escolha um cargo.");
            } else {
                f.insert(s);
                JOptionPane.showMessageDialog(null, "Servidor cadastrado com sucesso!");
                limparTelaAll();
            }
        } catch (ConexaoException ce) {
            JOptionPane.showMessageDialog(null, "Não foi possível conectar-se ao banco de dados!\n" + ce);
        } catch (ConsultaException e) {
            JOptionPane.showMessageDialog(null, "Não foi possível cadastrar o novo Servidor.\n" + e);
        } catch (GeralException ex) {
            JOptionPane.showMessageDialog(null, ex.getMessage());
            this.repaint();
        }

    }//GEN-LAST:event_btIncluirActionPerformed

    private void textCepActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_textCepActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_textCepActionPerformed

    private void btIncluirKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_btIncluirKeyPressed
        if (KeyEvent.getKeyText(evt.getKeyCode()).equals("Enter")) {
            btIncluirActionPerformed(null);
        }
    }//GEN-LAST:event_btIncluirKeyPressed

    private void btLimparKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_btLimparKeyPressed
        if (KeyEvent.getKeyText(evt.getKeyCode()).equals("Enter")) {
            btLimparActionPerformed(null);
        }
    }//GEN-LAST:event_btLimparKeyPressed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(ServidorCadastrar.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(ServidorCadastrar.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(ServidorCadastrar.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(ServidorCadastrar.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {

            @Override
            public void run() {
                new ServidorCadastrar().setVisible(true);
            }
        });
    }

    public void limparTela() {
        if (frameDadosPessoais.isShowing()) {
            textNome.setText("");
            textCpf.setText("");
            textEmail.setText("");
            textTel.setText("");
            textTel2.setText("");
            textBairro.setText("");
            textCep.setText("");
            textCidade.setText("");
            textEstado.setText("");
            textNumero.setText("");
            textRua.setText("");
        } else if (frameDadosProf.isShowing()) {
            textMatricula.setText("");
            textEmailProf.setText("");
            textTelSetor.setText("");
            cbCargoC.setSelectedIndex(-1);
            cbCargoE.setSelectedIndex(-1);
            cbLotacao.setSelectedIndex(-1);
        }
    }

    public void limparTelaAll() {
        textNome.setText("");
        textCpf.setText("");
        textEmail.setText("");
        textTel.setText("");
        textTel2.setText("");
        textBairro.setText("");
        textCep.setText("");
        textCidade.setText("");
        textEstado.setText("");
        textNumero.setText("");
        textRua.setText("");
        textMatricula.setText("");
        textEmailProf.setText("");
        textTelSetor.setText("");
        cbCargoC.setSelectedIndex(-1);
        cbCargoE.setSelectedIndex(-1);
        cbLotacao.setSelectedIndex(-1);
    }

    public final void carregarCombos() {
        Fachada fachada = new Fachada();
        Lotacao lot = new Lotacao();
        CargoEfetivo ce = new CargoEfetivo();
        CargoComissao cc = new CargoComissao();
        ArrayList<Lotacao> listaLot = new ArrayList<Lotacao>();
        ArrayList<CargoEfetivo> listaCe = new ArrayList<CargoEfetivo>();
        ArrayList<CargoComissao> listaCc = new ArrayList<CargoComissao>();
        try {
            listaLot = fachada.listar(lot);
            listaCe = fachada.listar(ce);
            listaCc = fachada.listar(cc);
        } catch (ConexaoException ex) {
            JOptionPane.showMessageDialog(null, "Não foi possível conectar-se ao banco de dados!\n" + ex);
        } catch (ConsultaException ex) {
            JOptionPane.showMessageDialog(null, "Ocorreu um erro ao tentar carregar a tela.\n" + ex);
        }
        for (int i = 0; i < listaLot.size(); i++) {
            cbLotacao.addItem(listaLot.get(i).getSigla());
        }
        for (int cE = 0; cE < listaCe.size(); cE++) {
            cbCargoE.addItem(listaCe.get(cE).getNome());
        }
        for (int cC = 0; cC < listaCc.size(); cC++) {
            cbCargoC.addItem(listaCc.get(cC).getNome());
        }
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btIncluir;
    private javax.swing.JButton btLimpar;
    private javax.swing.JComboBox cbCargoC;
    private javax.swing.JComboBox cbCargoE;
    private javax.swing.JComboBox cbLotacao;
    private javax.swing.JCheckBox checkEmail;
    private javax.swing.JPanel frameDadosPessoais;
    private javax.swing.JPanel frameDadosProf;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel30;
    private javax.swing.JLabel jLabel32;
    private javax.swing.JLabel jLabel33;
    private javax.swing.JLabel jLabel34;
    private javax.swing.JLabel jLabel35;
    private javax.swing.JLabel jLabel36;
    private javax.swing.JLabel jLabel37;
    private javax.swing.JLabel jLabel38;
    private javax.swing.JLabel jLabel39;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel40;
    private javax.swing.JLabel jLabel41;
    private javax.swing.JLabel jLabel42;
    private javax.swing.JLabel jLabel43;
    private javax.swing.JLabel jLabel44;
    private javax.swing.JLabel jLabel45;
    private javax.swing.JLabel jLabel46;
    private javax.swing.JLabel jLabel47;
    private javax.swing.JLabel jLabel48;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JTabbedPane jTabbedPane4;
    private javax.swing.JTextField textBairro;
    private javax.swing.JTextField textCep;
    private javax.swing.JTextField textCidade;
    private javax.swing.JTextField textCpf;
    private com.toedter.calendar.JDateChooser textData;
    private javax.swing.JTextField textEmail;
    private javax.swing.JTextField textEmailProf;
    private javax.swing.JTextField textEstado;
    private javax.swing.JTextField textMatricula;
    private javax.swing.JTextField textNome;
    private javax.swing.JTextField textNumero;
    private javax.swing.JTextField textRua;
    private javax.swing.JTextField textTel;
    private javax.swing.JTextField textTel2;
    private javax.swing.JTextField textTelFunc;
    private javax.swing.JTextField textTelSetor;
    // End of variables declaration//GEN-END:variables
}
